package com.partner.boot.controller;


import com.partner.boot.common.Result;
import com.partner.boot.entity.Comment;
import com.partner.boot.entity.CommentQuery;
import com.partner.boot.service.ICommentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    @GetMapping("/page")
    public Result readAdmins(Integer pageNum, Integer pageSize, CommentQuery query) {
        return Result.success(commentService.selectComment(pageNum,pageSize,query));
    }
    // 删除评论
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        commentService.deleteComment(id);
        return Result.success();
    }
    // 批量删除评论
    @PostMapping("/del/batch")
    public Result deletesById(@RequestBody Integer[] ids) {
        commentService.deletesComment(ids);
        return Result.success();
    }
    //添加评论
    @PostMapping
    public Result addComment(@RequestBody Comment comment){
        System.out.println(comment);
        commentService.addComment(comment);
        return Result.success();
    }
    //编辑评论
    @PutMapping
    public Result updateComment(@RequestBody Comment comment){
        commentService.updateComment(comment);
        return Result.success();
    }
}
